package cn.tedu.elasticsearch.repository;

import cn.tedu.elasticsearch.pojo.Item;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ItemRepository extends ElasticsearchRepository<Item,Long> {
    //我们继承了ElasticsearchRepository，就可以使用自动提供的增删改查的方法了
    //ElasticsearchRepository<[实体类类型],[主键类型]]>
    //自定义的单条件查询,需要遵循框架的使用规则
    //SELECT * FROM item where title like "%鼠标%";
    /*
       query:查询，对应SELECT
       Item/Items:指定返回类型是Item类型的，item是一个信息，items是多个
       By:通过，意思就是开始设置条件，类似where
       Title:要进行匹配的字段
       Matches: 开始匹配，类似like
     */
    List<Item> queryItemsByTitleMatches(String title);
    //多条件查询
    List<Item> queryItemsByTitleMatchesOrBrandMatches(String title,String brand);
    //排序查询
    List<Item> queryItemsByTitleMatchesOrBrandMatchesOrderByPriceDesc(String title,String brand);
    //分页查询
    Page<Item> queryItemsByTitleMatchesOrBrandMatches(String title, String brand, Pageable pageable);
}
